package com.example.notes;

import interfaces.Noteable;
import notes.NotesDatabase;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class SendMailActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_send_mail);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		
		final int position = getIntent().getIntExtra("CheckedIndex", 0);
		
		Noteable note = NotesDatabase.getNote(position);
		
		final TextView address = (TextView) findViewById(R.id.sendMailTo);
				
		final TextView text = (TextView) findViewById(R.id.sendTextViewText);
		text.setText(note.getText());
		final TextView title = (TextView) findViewById(R.id.sendTextViewTitle);
		title.setText(note.getTitle());
		
		
		Button sendButton = (Button) findViewById(R.id.sendButton);
		sendButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                
                emailIntent.setType("plain/text");
           
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
         
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title.getText().toString());
         
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, text.getText().toString());
                
                startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."), 1);

                
				finish();
			}
		});
		
		
	}
	
}
